package com.zjsos.governmentaffairs.sokettestapplication;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import com.zjsos.governmentaffairs.sokettestapplication.socketClientNew.NettyClientNew;
import com.zjsos.governmentaffairs.sokettestapplication.socketClientNew.NettyService;
import com.zjsos.governmentaffairs.sokettestapplication.webSocket.WebServiceClient;

import org.jeromq.ZMQ;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        WebServiceClient.getInstance().initSocket();

        test();

//        ZmqClient.instance().sendREQMessage(ZmqClient.START_REQ, "tcp://hq.panbao.top:5564");
//        ZmqClient.instance().sendREQMessage(ZmqClient.SEND_REQ_MSG, "9001,ag1903,2018-12-04 21:56:54,10");
//
//
//        ZmqClient.instance().sendSUBMessage(ZmqClient.START_SUB, "tcp://tick.panbao.top:5555");
//        ZmqClient.instance().sendSUBMessage(ZmqClient.SEND_SUB_MSG, "zn1902");

    }


    private void test() {
        new Thread(new Runnable() {

            public void run() {
                // TODO Auto-generated method stub
                ZMQ.Context context = ZMQ.context(1);  //创建1个I/O线程的上下文
                ZMQ.Socket subscriber = context.socket(ZMQ.SUB);     //创建一个sub类型，也就是subscriber类型的socket
                subscriber.connect("tcp://hq.panbao.top:5564");    //与在5555端口监听的publisher建立连接
                subscriber.subscribe("9001,ag1903,2018-12-04 21:56:54,10".getBytes());     //订阅fjs这个channel
                byte[] message = subscriber.recv();  //接收publisher发送过来的消息
                System.out.println("receive : " + new String(message));
                subscriber.close();
                context.term();
            }

        }).start();
    }


}
